package com.todaynews.ui.video;

import android.view.View;
import android.widget.Button;
import com.todaynews.R;
import com.todaynews.frame.model.InfoResult;
import com.todaynews.frame.okhttp.OkEntityListRequest;
import com.todaynews.frame.ui.fragment.BaseFragment;
import com.todaynews.model.model.News;

public class VideosListFragment extends BaseFragment {

    private String kw = "演唱会";//关键词
    private String uid = "5816621612";
    private String id = "6617951038169154051";
    private int pageToken = 1;//翻页值
    private static String code;
    private Button btn;

    public static VideosListFragment newInstance(String argument) {
        code = argument;
        return new VideosListFragment();
    }

    @Override
    public boolean isImmersionBarEnabled() {
        return false;
    }

    @Override
    public int getLayoutResId() {
        return R.layout.fragment_videos_list;
    }

    @Override
    public void bind(View view) {
        super.bind(view);
        btn = view.findViewById(R.id.btn);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                getVideos(pageToken);
            }
        });
    }

    @Override
    public void init() {

    }

    @Override
    public void loadData() {

    }

    @Override
    protected void onSuccess(int what, InfoResult t) {

    }

    @Override
    protected void onFail(int what, InfoResult t) {

    }

    private void getVideos(int pageToken) {
        OkEntityListRequest<News> request = new OkEntityListRequest<>(R.id.getVideos,
                getUrl(pageToken), News.class);
        requestOkhttpEntityList(request);
    }

    private String getUrl(int pageToken){

        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("http://api01.idataapi.cn:8000/video/toutiao?apikey=nKx0OXUIHMDnRA0HkJRZc5tR2MEScpcPNgurw0xDfPu4b9Rrskyw40tv45aPu2j7");

        stringBuffer.append("&");
        stringBuffer.append("uid=");
        stringBuffer.append(uid);

        stringBuffer.append("&");
        stringBuffer.append("id=");
        stringBuffer.append(id);

        stringBuffer.append("&");
        stringBuffer.append("pageToken=");
        stringBuffer.append(pageToken);

        return stringBuffer.toString();
    }
}
